# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_bootstrapping=no

_realname=tomli
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.0.1
pkgrel=5
pkgdesc="A lil' TOML parser (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/hukkin/tomli'
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
if [[ "${_bootstrapping}" == "no" ]]; then
  makedepends=(
    "${MINGW_PACKAGE_PREFIX}-python-build"
    "${MINGW_PACKAGE_PREFIX}-python-installer"
    "${MINGW_PACKAGE_PREFIX}-python-flit-core")
fi
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest" 
              "${MINGW_PACKAGE_PREFIX}-python-dateutil")
source=("${_realname}-$pkgver.tar.gz"::"$url/archive/$pkgver.tar.gz"
        "https://pypi.debian.net/tomli/tomli-$pkgver-py3-none-any.whl"
        "install_wheel.py")
sha256sums=('ad22dbc128623e0c156ffaff019f29f456eba8a5d5a05164dd34f63e560449df'
            '939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc'
            '668e64f912d6360330c403edb6100b21f6aa6dd6a7803d342fab8c35d8176ad9')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
  cd "python-build-${MSYSTEM}"

  if [[ "${_bootstrapping}" == "no" ]]; then
    python -m build --wheel --skip-dependency-check --no-isolation
  else
    mkdir dist
    cp "${srcdir}/tomli-$pkgver-py3-none-any.whl" dist
  fi
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  python -m pytest
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  if [[ "${_bootstrapping}" == "no" ]]; then
    MSYS2_ARG_CONV_EXCL="--prefix=" \
      python -m installer --prefix=${MINGW_PREFIX} --destdir="${pkgdir}" dist/*.whl
  else
    _pythonpath=`python -c "import sysconfig; print(sysconfig.get_path('platlib'))"`
    _site_packages="${pkgdir}$(cygpath ${_pythonpath})"
    mkdir -p "$_site_packages"
    python "${srcdir}/install_wheel.py" -i"${_site_packages}" dist/*.whl
    MSYS2_ARG_CONV_EXCL="-p" python -m compileall \
      -o 0 -o 1 -q -s"${pkgdir}" -p"/" "${pkgdir}${MINGW_PREFIX}/lib/python"*
  fi

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
